var {Response} = require('ringo/webapp/response');

exports.index = function (req) {
    return Response.skin(module.resolve('skins/index.html'), {
        title: "It's working!"
    });
};

exports.test = function (req) {
    return Response.skin(module.resolve('skins/index.html'), {
        title: "てすと！"
    });
};

var model = require('./model');

// 「～/select/N」：N件目のauthorをウェルカムする。
// 「～/select」 ：1件目のauthorをウェルカムする。
exports.select = function(req ,id){
	
	var posts = model.Post.query().select();
	
	print(posts);
	
	if(id == undefined){
		var author = posts[0].author
	} else {
		var author = posts[id].author
	}
	
	return Response.skin('skins/index.html', {
		title: "Welcome " + author,
	});
};

// 登録値のリストを出す
exports.postList = function(req){
	
	var posts = model.Post.query().select().slice(0,10);
	
	print(posts);
	
	return Response.skin('skins/postList.html',{
		title: "post test",
		posts :posts,
	});
};

exports.post = function(req, id){
	
	var post = model.Post.get(id);
	
	return Response.skin('skins/post.html',{
		post:post,
	});
};
